package com.gillion.grape.fros.ui.wizards;

import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;


public class NewWEFPage extends WizardPage {
	public static final String PAGE_NAME="New Fros page";
	private Text txtProjectName;
	private Text txtNameSpace;
	private Text dbName;
	private Text url;
	private Text userName;
	private Text password;
	private Combo driverClass;
	

	protected NewWEFPage() {
		super(PAGE_NAME);
	}
	
	public String getProjectName(){
		return txtProjectName.getText();
	}
	
	public String getNameSpace(){
		return txtNameSpace.getText();
	}
	
	public String getDbName(){
		return dbName.getText();
	}
	
	public String getUrl(){
		return url.getText();
	}
	
	public String getUserName(){
		return userName.getText();
	}
	
	public String getPassword(){
		return password.getText();
	}
	
	public String getDriverClass(){
		return driverClass.getText();
	}

	@Override
	public void createControl(Composite parent) {
	    Composite composite = new Composite(parent, SWT.NONE);
	    composite.setLayout(new GridLayout(2, false));
	    setControl(composite);
	    
	    // 工程名称
	    new Label(composite,SWT.LEFT).setText("工程名称");
	    txtProjectName = new Text(composite, SWT.BORDER | SWT.SINGLE);
	    txtProjectName.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
	    txtProjectName.addModifyListener(new ModifyListener() {
	      public void modifyText(ModifyEvent event) {
	        String s = ((Text) event.widget).getText();
	        if (s == null || s.length() == 0){
	          setErrorMessage("必须输入工程名称");
	        } else {
	          setErrorMessage(null);
	        }
	      }
	    });

	    if(txtProjectName.getText()==null||txtProjectName.getText().trim().length()==0){
	    	setErrorMessage("必须输入工程名称");
	    }
	
	    new Label(composite,SWT.LEFT).setText("命名空间");
	    txtNameSpace = new Text(composite, SWT.BORDER | SWT.SINGLE);
	    txtNameSpace.setText("com.fros");
	    txtNameSpace.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
	    txtNameSpace.addModifyListener(new ModifyListener() {
		      public void modifyText(ModifyEvent event) {
		        String s = ((Text) event.widget).getText();
		        if (s == null || s.length() == 0){
		          setErrorMessage("必须输入命名空间");
		        } else {
		          setErrorMessage(null);
		        }
		      }
		    });
	    
	    new Label(composite,SWT.LEFT).setText("数据库驱动");
	    driverClass = new Combo(composite, SWT.BORDER | SWT.SINGLE);
	    driverClass.add("oracle");
	    driverClass.add("mysql");
	    driverClass.select(0);
	    driverClass.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
	    driverClass.addModifyListener(new ModifyListener() {
		      public void modifyText(ModifyEvent event) {
		        String s = ((Text) event.widget).getText();
		        if (s == null || s.length() == 0){
		          setErrorMessage("必须输入数据库驱动");
		        } else {
		          setErrorMessage(null);
		        }
		      }
		    });
	    
	    
	    new Label(composite,SWT.LEFT).setText("数据库IP");
	    url = new Text(composite, SWT.BORDER | SWT.SINGLE);
	    url.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
	    url.addModifyListener(new ModifyListener() {
		      public void modifyText(ModifyEvent event) {
		        String s = ((Text) event.widget).getText();
		        if (s == null || s.length() == 0){
		          setErrorMessage("必须输入数据库IP");
		        } else {
		          setErrorMessage(null);
		        }
		      }
		    });
	    
	    new Label(composite,SWT.LEFT).setText("数据库名");
	    dbName = new Text(composite, SWT.BORDER | SWT.SINGLE);
	    dbName.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
	    dbName.addModifyListener(new ModifyListener() {
		      public void modifyText(ModifyEvent event) {
		        String s = ((Text) event.widget).getText();
		        if (s == null || s.length() == 0){
		          setErrorMessage("必须输入数据库名");
		        } else {
		          setErrorMessage(null);
		        }
		      }
		    });
	    
	    new Label(composite,SWT.LEFT).setText("数据库用户名");
	    userName = new Text(composite, SWT.BORDER | SWT.SINGLE);
	    userName.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
	    userName.addModifyListener(new ModifyListener() {
		      public void modifyText(ModifyEvent event) {
		        String s = ((Text) event.widget).getText();
		        if (s == null || s.length() == 0){
		          setErrorMessage("必须输入数据库用户名");
		        } else {
		          setErrorMessage(null);
		        }
		      }
		    });
	    
	    new Label(composite,SWT.LEFT).setText("数据库密码");
	    password = new Text(composite, SWT.BORDER | SWT.SINGLE);
	    password.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
	    password.addModifyListener(new ModifyListener() {
		      public void modifyText(ModifyEvent event) {
		        String s = ((Text) event.widget).getText();
		        if (s == null || s.length() == 0){
		          setErrorMessage("必须输入数据库密码");
		        } else {
		          setErrorMessage(null);
		        }
		      }
		    });
	}
}
